<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">添加写真图集</h3>
                </div>
                <form id="addInfo" class="form-horizontal" role="form" onsubmit="javascript:saveInfo();">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">套图名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="name" class="form-control" name="name"
                                       placeholder="视频名称">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="cover" class="col-sm-2 control-label">套图封面：</label>
                            <div class="col-md-8">
								<input type="file" class="file-loading" id="coverFile" accept="image/*">
								<input type="text" class="form-control input-sm" id="coverUrl" name="cover"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="picType" class="col-sm-1 control-label">图片分类：</label>
							  <div class="col-sm-8 ">
                             <select id="picType" name="picType" class="form-control select2">
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="type" class="col-sm-1 control-label">状态：</label>
							  <div class="col-sm-8 ">
                             <select id="type" name="type" class="form-control select2">
                               	<option value="1" selected='selected'>banner</option>
                                <option value="2">图片列表</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
function findPicType(){
	$.ajax({
		type:"post",
		url:"<%=path%>/dictionary/children_json?parentId="+1,
		dataType:"json",
		success: function(data){
			var optionstring = "";
			$.each(data.rows, function(i,val){
				 optionstring += "<option value=\"" + val.value + "\" >" + val.childName + "</option>";
			});
			 $("#picType").html(optionstring);  
		   }
		});
}

$(function(){
	findPicType();
	//封面上传
   $("#coverFile").fileinput({
   	uploadUrl:"<%=path%>/portrait/pictures/uploadClassifyImg",
       browseClass: "btn btn-primary",
       enctype: 'multipart/form-data',
       autoReplace:true,
       dropZoneEnabled:false,
       browseLabel: "上传",
       showCaption: false,
       showRemove: false,
       showUpload: true,
       showZoom:false,
       maxFileCount:1, ////表示允许同时上传的最大文件个数
       allowedFileTypes:["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
       previewSettings:{
       	image: {width: "auto", height: "100px"},
       },
   });
   $('#coverFile').on('fileuploaded', function(event, data, previewId, index) {
   	var path = data.response.initialPreviewConfig[0].extra.path;
       $("#coverUrl").val(path);
   });
   $('#coverFile').on('filedeleted', function(event,key,jqXHR,data) {
   	if($("#coverUrl").val()==data.path)
   		$("#coverUrl").val('');
   });
});
	function saveInfo(){
		var cover = $("#coverUrl").val();
		var name = $("#name").val();
		var picType = $("#picType").val();
		var type= $("#type").val();
		$.ajax({
			type:"post",
			async: false,
			url:"<%=path%>/portrait/pictures/addPicturesSave",
			data:{cover:cover,
				name:name,
				picType:picType,
				type:type},
			dataType:"json",
			success: function(data){
				if (data.missage == "success") {
                    modalMsg("新增成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "error"){
                	 modalMsg("新增失败", "error");
                }else{
                	 modalMsg("更新失败", "error");
                }
			}
		});
	}
</script>
</body>
</html>